import 'package:flutter_admin/utils/utils.dart';

class MpsReplenishment {
  String? id;
  String? productName;
  String? defaultCode;
  String? description;
  String? uom;
  String? qtyFree;
  String? qtyTransit;
  String? qtyDemand;
  String? qtyOrder;

  MpsReplenishment({
    this.id,
    this.productName,
    this.defaultCode,
    this.description,
    this.uom,
    this.qtyFree,
    this.qtyTransit,
    this.qtyDemand,
    this.qtyOrder,
  });

  MpsReplenishment copyWith({
    String? id,
  }) {
    return new MpsReplenishment(
      id: id ?? this.id,
    );
  }

  @override
  String toString() {
    return '''MpsReplenishment{
      id: id,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is MpsReplenishment &&
          runtimeType == other.runtimeType &&
          id == other.id);

  factory MpsReplenishment.fromMap(Map<String, dynamic> map) {
    return new MpsReplenishment(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      description: map['description'] != false
          ? map['description'].toString() as String?
          : "",
      productName: map['product_name'] != false
          ? map['product_name'].toString() as String?
          : "",
      defaultCode: map['default_code'] != false
          ? map['default_code'].toString() as String?
          : "",
      uom: map['uom_id'] != false ? map['uom_id'][1].toString() as String? : "",
      qtyDemand: map['qty_demand'] != false
          ? map['qty_demand'].toString() as String?
          : "",
      qtyFree:
          map['qty_free'] != false ? map['qty_free'].toString() as String? : "",
      qtyTransit: map['qty_transit'] != false
          ? map['qty_transit'].toString() as String?
          : "",
      qtyOrder: map['qty_order'] != false
          ? map['qty_order'].toString() as String?
          : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'productName': this.productName,
      'defaultCode': this.defaultCode,
      'description': this.description,
      'uom': this.uom,
      'qtyFree': this.qtyFree,
      'qtyTransit': this.qtyTransit,
      'qtyDemand': this.qtyDemand,
      'qtyOrder': this.qtyOrder,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      // ['ordered', '=', false],
      if (this.productName != null && this.productName != '')
        ['product_name', 'like', '%${this.productName}%'],
      if (this.defaultCode != null && this.defaultCode != '')
        ['default_code', 'like', '%${this.defaultCode}%'],
    ] as List;
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
    } as Map<String, dynamic>;
  }
}
